/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2023-11-21
 * Time: 19:17
 */
public class Solution {
    public void merge(int A[], int m, int B[], int n) {
        A = new int[m+n];
        //用来遍历A
        int pos = 0;
        //用来遍历数组B
        int k = 0;
        while(pos != m && k != n) {
            //如果找到A数组上位置>= 当前B数组上的位置，从pos位置开始的所有元素向后移动一位
            if(A[pos] >= B[k]) {
                for(int i = m - 1 + k; i>= pos; i--) {
                    A[i + 1] = A[i];
                }
                A[pos] = B[k];
                k++;
            }else {
                pos++;
            }
        }

        if(pos == m) {
            while(k != n) {
                A[pos +1] += B[k];
                k++;
            }
        }
    }
}